/* ===============================================================================  
 * Copyright (c) 2010 Acid Frameworks
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * =============================================================================== */

using System;
using System.Windows.Forms;

using Acid.Multimedia.DirectShow;

namespace Acid.Multimedia.Video
{
    public partial class DeviceSelect : Form
    {
        #region Drivers
        private class ComboBoxOption
        {
            public string   name;
            
            public DsDevice device;

            public ComboBoxOption(string name, DsDevice device)
            {
                this.device = device;
                this.name = name;
            }
            public string Name
            {
                get { return this.name; }
            }

            public DsDevice Device
            {
                get { return this.device; }
            }

            public override string ToString()
            {
                return this.Name;
            }
        }
        #endregion

        private DsDevice dsdevice;
        
        public DeviceSelect()
        {
            InitializeComponent();
        }
        
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            DsDevice[] capDevicesDsDevice = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

            foreach (DsDevice device in capDevicesDsDevice)
            {
                this.comboBox1.Items.Add(new ComboBoxOption(device.Name, device));
            }
        }

        public DsDevice Device
        {
            get { return this.dsdevice; }
        }

        #region Events

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex != -1)
            {
                ComboBoxOption option = (ComboBoxOption)this.comboBox1.Items[this.comboBox1.SelectedIndex];

                this.dsdevice = option.device;

                this.DialogResult = DialogResult.OK;

                this.Close();
            }
            else
            {
                MessageBox.Show("You must select a video device");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;

            this.Close();
        }

        #endregion
    }
}